
if("undefined" == typeof click_id){
var click_id = "";
var click_name = "";
var destination_id = "";
}

function click_user(data){
	var click_id = top.document.getElementById(destination_id+"_select_id").value;
	var click_name = $("#"+destination_id+"_select_user").val();

	if(click_id.indexOf(","+data.id+",")>0 || click_id.indexOf(data.id+",")==0)//源表单数据位0个或多于0个执行以下操作
	{
    	if(click_id.indexOf(data.id+",")==0)
		{
			click_id = click_id.replace(data.id+",","");
			click_name = click_name.replace(data.user_name+",","");
			//borderize_off(targetelement);
			//$(targetelement).removeClass("active");
		}
		if(click_id.indexOf(","+data.id+",")>0)
		{
			click_id = click_id.replace(","+data.id+",",",");
			click_name = click_name.replace(","+data.user_name+",",",");
		}
	}else{
		click_id+=data.id+",";
		click_name+=data.user_name+",";
	}
	$("#"+destination_id+"_select_id").val(click_id);
	$("#"+destination_id+"_select_user").val(click_name);
}
  

function begin_set(){
	var rows;
	var click_id = $("#"+destination_id+"_select_id").val();
	var rows = $("#selectuser_list").datagrid("getRows"); 
	for(var i=0;i<rows.length;i++){
		//获取每一行的数据
		//alert(rows[i].id);//假设有id这个字段
		if(click_id.indexOf(","+rows[i].id+",")>0 || click_id.indexOf(rows[i].id+",")==0)
		 	$('#selectuser_list').datagrid("selectRow", i);
		else
			$('#selectuser_list').datagrid("unselectRow", i);
	}
}


function add_all(ele){
	var click_id = top.document.getElementById(destination_id+"_select_id").value;
	var click_name = $("#"+destination_id+"_select_user").val();

	for (var step_i=0; step_i<ele.id.length; step_i++)	{
		var id=ele.id[step_i];
		user_name=ele.name[step_i];
		if(click_id.indexOf(","+id+",")<0 && click_id.indexOf(id+",")!=0){
			click_id+=id+",";
			click_name+=user_name+",";
			//borderize_on(ele[step_i]);
			//$(ele[step_i]).addClass("active");			  
		}
	}
	$("#"+destination_id+"_select_id").val(click_id);
	$("#"+destination_id+"_select_user").val(click_name);
	begin_set();
}



function del_all(ele){
	for (step_i=0; step_i<ele.id.length; step_i++)	{
		var click_id = top.document.getElementById(destination_id+"_select_id").value;
		var click_name = $("#"+destination_id+"_select_user").val();

		var id=ele.id[step_i];
		user_name=ele.name[step_i];
		if(click_id.indexOf(id+",")==0){
			click_id=click_id.replace(id+",","");
			click_name=click_name.replace(user_name+",","");
			//borderize_off(ele[step_i]);
			//$(ele[step_i]).removeClass("active");
		}
		if(click_id.indexOf(","+id+",")>0){
			click_id=click_id.replace(","+id+",",",");
			click_name=click_name.replace(","+user_name+",",",");
			//borderize_off(ele[step_i]);
			//$(ele[step_i]).removeClass("active");
		}
		$("#"+destination_id+"_select_id").val(click_id);
		$("#"+destination_id+"_select_user").val(click_name);
	}
	begin_set();
}

//清空选择的用户
function clearuser(){
	$("#"+destination_id+"_select_id").val('');
	$("#"+destination_id+"_select_user").val('')
	begin_set();
}

//刷新两个区域，并定义标题和插入位置，弹出人员选择窗口，
function selectuser_fun(t,v){
	$('#selectuser_tooltip_'+v).tooltip('destroy');//销毁选择用户提示
	//$('#selectuser_tree').tree('reload');
	var nodes = $('#selectuser_tree').tree('getChecked');
	for(var i = 0;i < nodes.length; i++){
		$('#selectuser_tree').tree('uncheck',nodes[i].target);
	}
	//$('#selectuser_tree').tree('uncheck', node.target);
	$('#selectuser_list').datagrid('unselectAll');
	
	destination_id = v;
	if(v === 'worklog_manage_search'){
		$('#selectuser_dd_stint').dialog({
			title: t
		});
		$('#selectuser_dd_stint').dialog('open');
	}else{
		$('#selectuser_dd').dialog({
			title: t
		});
		$('#selectuser_dd').dialog('open');
	}
	begin_set();//设置已选的用户为选中状态
}

//提示选择收件人
function selectuser_tooltip(t,v){
	$('#selectuser_tooltip_'+v).tooltip({
		position: 'right',
		content: '<span style="color:#fff">'+t+'</span>',
		onShow: function(){
			$(this).tooltip('tip').css({
				backgroundColor: '#666',
				borderColor: '#666'
			});
		}
	});
}
/*
function emailinuser(v){//刷新两个区域，并定义标题和插入位置，弹出人员选择窗口，
	$('#selectuser_tree').tree('reload');
	$('#selectuser_list').datagrid('reload');
	var title;
	if(v === 'email_add_sj'){
		title = '收件人';
		destination_id = 'email_add_sj';
	}else{
		title = '抄送人';
		destination_id = 'email_add_cc';
	}
	$('#selectuser_dd').dialog({
		title: '选择'+title
	});
	$('#selectuser_dd').window('open');
}
*/